#ifndef INFOBOARD_H
#define INFOBOARD_H

#include <QGraphicsObject>
#include <QFont>
#include "gs.h"
#include "gameboardorganizer.h"
#include "gameboarditem.h"
#include "gameanimation.h"

using namespace gs;

namespace gs
{

/* Followings are the components for InfoBoard */

/* Ghost resistance QGraphicsObject */
class ResistItem : public GameBoardItem
{
    Q_OBJECT

public:
    ResistItem( GameBoardOrganizer * );
    QRectF boundingRect() const { return QRectF( -_w/2, -_h/2, _w, _h ); }
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);

    void setResistance( QPixmap pixmap ) { _qp = pixmap; _null = false; }
    void setNull( bool null = true );
public slots:
    void animate();
signals:
    void half_finished();
    void manual_stopped();
private:
    QPixmap _qp;
    bool _null;
    QPropertyAnimation *_anim_0, *_anim_1, *_anim_2;
    QSequentialAnimationGroup *_anim_group_0;
    QParallelAnimationGroup *_anim_group_main;
    const static int _w = 25, _h = 40;
};

/* Ghost resistances QGraphicsObjects (manage the group of resistances) */
class ResistItemGroup : public GameBoardOrganizer
{
    Q_OBJECT

public:
    ResistItemGroup( GameTable *, GameBoardOrganizer * );
    QRectF boundingRect() const;
    void paint(QPainter *, const QStyleOptionGraphicsItem *, QWidget *) {}
    void setGhost( Ghost* );
public slots:
    void updateState();
private:
    int _resist0;
    int _resist1;
    int _resist2;
    int _resist3;
    int _resist4;
    int _total_resist;
    QList <ResistItem*> _items;
    const static int _hgap = -10, _vgap = 2;
    QPixmap _qp0, _qp1, _qp2, _qp3, _qp4;
};

/* Ghost card QGraphicsObject */
class GhostCard : public GameBoardItem
{
    Q_OBJECT

public:
    GhostCard( GameBoardOrganizer * );
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    void setGhost( Ghost *ghost );
    int  width() { return _width; }
    int  height() { return _height; }
protected:
    void mousePressEvent( QGraphicsSceneMouseEvent * )
    {
        emit clicked();
    }
    void hoverEnterEvent( QGraphicsSceneHoverEvent * )
    {
        update();
        emit hover_entered();
    }

    void hoverLeaveEvent( QGraphicsSceneHoverEvent * )
    {
        update();
        emit hover_left();
    }

signals:
    void clicked();
    void hover_entered();
    void hover_left();
private:
    Ghost *_ghost;
    QPixmap _qpcard, _qpbg;
    QPixmap _qpboss;
    QPixmap _rib0, _rib1, _rib2, _rib3, _rib4;
    Qt::GlobalColor _color;
    const static int _width = 120, _height = 120;
    const static int _xoff = 50, _yoff = 20;
    qreal _scale;
};

/* Ghost skill slot QGraphicsObject */
class GhostSkillSlot : public GameBoardItem
{
    Q_OBJECT
public:
    GhostSkillSlot( GameBoardOrganizer * );
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    void setSkill( GhostSkills skills );
    static QPixmap SkillQPixmap( GhostSkills skills );
    int _w, _h;
private:
    GhostSkills _skill;
    QPixmap _bg, _qpskill;
    int _iconw, _iconh;
};

/* Ghost skill slot QGraphicsObject (for grouping the skills) */
class GhostSkillSlotGroup : public GameBoardOrganizer
{
    Q_OBJECT
public:
    GhostSkillSlotGroup( GameTable *, GameBoardOrganizer *  );
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    void setGhost( Ghost* ghost );
private:
    Ghost* _ghost;
    GhostSkillSlot *_skill_slot_l;
    GhostSkillSlot *_skill_slot_m;
    GhostSkillSlot *_skill_slot_r;
    int _w, _h;
    const static int HGAP = 20;
};



/*
    GhostInfo class(es)
*/
/* displays Ghost card info ( or even player info ) */
class InfoBoard : public GameBoardOrganizer
{
    Q_OBJECT
public:
    InfoBoard( GameTable *, GameBoardOrganizer * );
    QRectF boundingRect() const;
    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
    Ghost* currentGhost();
    int width()  { return INFO_WIDTH;  }
    int height() { return INFO_HEIGHT; }
public slots:
    void setGhost( Ghost* ghost );
protected slots:
    void fadeFinished();
signals:
    void ghostChanged();
protected:
    QPixmap _bg;
    Ghost* _dghost, *_ghost;
    GhostCard*  _carditem;
    GhostSkillSlotGroup* _skillitem;
    ResistItemGroup*     _resistitem;
    QFont _font;
    QPropertyAnimation *_anim_card0, *_anim_card1;
    int INFO_WIDTH;
    int INFO_HEIGHT;
};

/* interactive the ghost card deck */
class DeckBoard : public InfoBoard
{
    Q_OBJECT
public:
    DeckBoard( GameTable *, GameBoardOrganizer * );
    void   link_to_info( InfoBoard * );
    void   flip();
    Ghost* pop();
    void   newDeck();
    bool   empty() { return _deck.empty(); }
public slots:
    void   clicked();
    void   hover_in();
    void   hover_out();
signals:
    void   bossInvoked();
private:
    QList <Ghost*> _deck;
    InfoBoard * _info_board;
    bool _fliped;
};

}
#endif // INFOBOARD_H
